<template>
  <div class="flutter-navigation-container">
    <h1 class="page-title">Flutter社区</h1>
    
    <!-- 官网分类 -->
    <h2 class="category-title">官网</h2>
    <div class="cards-container">
      <div 
        v-for="site in officialSites" 
        :key="site.id" 
        class="card"
        @click="goToSite(site.url)"
      >
        <img :src="site.image" :alt="site.title" class="card-image" />
        <div class="card-content">
          <h3 class="card-title">{{ site.title }}</h3>
          <p class="card-description">{{ site.description }}</p>
        </div>
      </div>
    </div>
    
    <!-- 博客分类 -->
    <h2 class="category-title">博客</h2>
    <div class="cards-container">
      <div 
        v-for="site in blogSites" 
        :key="site.id" 
        class="card"
        @click="goToSite(site.url)"
      >
        <img :src="site.image" :alt="site.title" class="card-image" />
        <div class="card-content">
          <h3 class="card-title">{{ site.title }}</h3>
          <p class="card-description">{{ site.description }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: 'FlutterNavigation',
  data() {
    return {
      sites: [
        {
          id: 1,
          title: 'Flutter中文官网',
          description: 'Flutter中文官方网站',
          url: 'https://flutter.cn/',
          image: 'https://files.flutter-io.cn/flutter-cn/landing/ec64036b4eacc9f3fd73.svg'
        },
        {
          id: 2,
          title: 'Flutter英文官网',
          description: 'Flutter官方文档',
          url: 'https://docs.flutter.dev/',
          image: 'https://storage.googleapis.com/cms-storage-bucket/4fd5520fe28ebf839174.svg'
        },
        {
          id: 3,
          title: 'Flutter仓库',
          description: 'Dart和Flutter包管理平台',
          url: 'https://pub.dev/',
          image: 'https://pub.dev/static/hash-pqg4tc09/img/pub-dev-logo.svg'
        },
        {
          id: 4,
          title: 'Flutter实战',
          description: 'Flutter实战书籍在线阅读',
          url: 'https://book.flutterchina.club/',
          image: 'https://book.flutterchina.club/assets/img/logo.png'
        },
        {
          id: 5,
          title: 'Flutter教程',
          description: '郭霖Flutter系列教程',
          url: 'https://guoshuyu.cn/home/wx/Flutter-1.html',
          image: 'https://docs.flutter.dev/assets/images/branding/flutter/logo/default.svg'
        }
      ]
    }
  },
  computed: {
    officialSites() {
      return this.sites.filter(site => site.id <= 3);
    },
    blogSites() {
      return this.sites.filter(site => site.id > 3);
    }
  },
  methods: {
    goToSite(url: string) {
      window.open(url, '_blank');
    }
  }
}
</script>

<style scoped>
.flutter-navigation-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.page-title {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
}

.category-title {
  font-size: 24px;
  margin: 30px 0 15px 0;
  color: #333;
  border-left: 4px solid #007bff;
  padding-left: 10px;
}

.cards-container {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 20px;
}

.card {
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  background-color: #fff;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}

.card-image {
  width: 100%;
  height: 120px;
  object-fit: contain;
  padding: 15px;
  background-color: #828282;
}

.card-content {
  padding: 15px;
}

.card-title {
  font-size: 16px;
  margin: 0 0 8px 0;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-description {
  font-size: 12px;
  color: #666;
  margin: 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 1200px) {
  .cards-container {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 992px) {
  .cards-container {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .cards-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 576px) {
  .cards-container {
    grid-template-columns: 1fr;
  }
}
</style>